﻿package {
    import flash.display.Bitmap;
    import flash.display.GradientType;
    import flash.display.Shape;
    import flash.display.Sprite;
    import flash.geom.Matrix;
    import flash.events.Event;
	import uk.co.bigroom.display.RadialPerlin;
    
    public class RadialPerlinDemo extends Sprite
    {
    	private var perl:RadialPerlin;
		private var offsetDistance:Number = 0;
		private var offsetRotation:Number = 0;
		
        public function RadialPerlinDemo()
        {
            createImage();
            createPerlin();
            addEventListener( Event.ENTER_FRAME, enterFrame, false, 0, true );
        }
        
        public function enterFrame( ev:Event ):void
		{
			offsetDistance += 2;
			offsetRotation += 4;
			perl.draw( offsetDistance, offsetRotation );
		}

		private function createPerlin():void
		{
			perl = new RadialPerlin( 100, 3, Math.random() * 1000, false, 15, false, true );
			perl.draw( offsetDistance, offsetRotation );
			var bmp:Bitmap = new Bitmap( perl.bitmapData );
			addChild( bmp );
		}
		
        private function createImage():void
        {
        	var sp:Shape = new Shape();
        	var colours:Array = [0xFF9900,0xCC6600];
			var alphas:Array = [1,0];
			var ratios:Array = [0,255];			
			var mat:Matrix = new Matrix();
			mat.createGradientBox( 200, 200, 0, 0, 0 );
			sp.graphics.beginGradientFill( GradientType.RADIAL, colours, alphas, ratios, mat );
			sp.graphics.drawCircle( 100, 100, 100 );
			sp.graphics.endFill();
			addChild( sp );
        }
    }
}

